package cn.z2huo.knowledge.concurrency.countdownlatch.demo;

import java.util.concurrent.CountDownLatch;

/**
 * <p>
 *
 * @author z2huo
 */
class Driver {

    void doSomethingElse() {
        System.out.println("doSomethingElse");
    }

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch startSignal = new CountDownLatch(1);
        CountDownLatch doneSignal = new CountDownLatch(10);

        for (int i = 0; i < 10; ++i) {
            new Thread(new Worker(startSignal, doneSignal)).start();
        }

        Driver driver = new Driver();

        // 不让线程运行
        driver.doSomethingElse();
        // 让所有线程继续
        startSignal.countDown();
        driver.doSomethingElse();
        // 等待所有线程完成
        doneSignal.await();
    }

}
